#pragma once


#include "ScriptCompiler/AST/ASTNode.h"
#include "ScriptCompiler/Token/Token.h"

class CScriptFileContext;

class IASTBuilder
{

public:
    virtual bool ReadCurentToken()=0;

    //find  next paired "}" 
    static TOptional<uint64_t> FindPairedBrace(
        std::shared_ptr<CScriptFileContext> InContext
        );

    //find  next paired "}" 
    static TOptional<uint64_t> FindPairedBrace(
        int32_t InStartIndex,
        std::shared_ptr<CScriptFileContext> InContext
    );

    //find  next paired ")"
    static TOptional<uint64_t> FindPairedParentheses(
        std::shared_ptr<CScriptFileContext> InContext
        );

    //find  next paired ")"
    static TOptional<uint64_t> FindPairedParentheses(
        int32_t InStartIndex,
        std::shared_ptr<CScriptFileContext> InContext
        );    
    
    //find  next paired "]"
    static TOptional<uint64_t> FindPairedBracket(
        std::shared_ptr<CScriptFileContext> InContext
        );

    //find  next paired "]"
    static TOptional<uint64_t> FindPairedBracket(
        int32_t InStartIndex,
        std::shared_ptr<CScriptFileContext> InContext
        );

    //find  next paired ">"
    static TOptional<uint64_t> FindPairedAngleBracket(
        std::shared_ptr<CScriptFileContext> InContext
        );

    //find  next paired ">"
    static TOptional<uint64_t> FindPairedAngleBracket(
        int32_t InStartIndex,
        std::shared_ptr<CScriptFileContext> InContext
        );

    // find next token with specific type
    // return index of token 
    static TOptional<uint64_t> FindNextToken(
        EScriptTokenType TokenType,
        std::shared_ptr<CScriptFileContext> InContext
        );

    //InEndIndex is the end index of the search range
    static TOptional<uint64_t> FindNextToken(
        EScriptTokenType TokenType,
        std::shared_ptr<CScriptFileContext> InContext
        ,uint64_t InEndIndex
        );

    static TOptional<uint64_t> FindNextToken(
        TVector<EScriptTokenType> TokenTypes,
        std::shared_ptr<CScriptFileContext> InContext
        ,uint64_t InStartIndex
        ,uint64_t InEndIndex
        );

    // find next  AssigmentOperator token ( = += -= *= /= )
    // return index of token
    static TOptional<uint64_t> FindNextAssigmentOperator(
        std::shared_ptr<CScriptFileContext> InContext
        ,uint64_t InEndIndex
        );


    
    // find  next paired "}"  ")" "]" ">" token
    // return index of paired token
    static TOptional<uint64_t> FindPairedToken(
        EScriptTokenType LeftTokenType,
        EScriptTokenType RightTokenType,
        std::shared_ptr<CScriptFileContext> InContext
        );

    // find  next paired "}"  ")" "]" ">" token
    // return index of paired token
    static TOptional<uint64_t> FindPairedToken(
        EScriptTokenType LeftTokenType,
        EScriptTokenType RightTokenType,
        int32_t InStartIndex,
        std::shared_ptr<CScriptFileContext> InContext
        );

};


void BuildAST(std::shared_ptr<CScriptFileContext> InContext);

